home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / t_unix / j109lxa4.tar / dumbcons.c < prev    next >
C/C++ Source or Header  |  1994-06-04  |  4KB  |  228 lines

  1. /*
  2.  * A "dumb console" session manager.  This is intended for use when stdin/out
  3.  * aren't ttys.  But stdin must still be usable for input.
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <sys/types.h>
  8. #include <termios.h>
  9. #include "config.h"
  10. #include "hardware.h"
  11. #include "proc.h"
  12. #include "socket.h"
  13. #include "tty.h"
  14. #include "sessmgr.h"
  15.  
  16. #ifdef SM_DUMB
  17.  
  18. static struct termios old_tty, new_tty;
  19. static int Suspense, ttyed;
  20.  
  21. static int
  22. dumb_init(const struct sessmgr_sw *sm)
  23. {
  24.     extern int Numrows, Numcols;
  25.  
  26.     if ((ttyed = (tcgetattr(0, &old_tty) != -1)))
  27.     {
  28.     new_tty = old_tty;
  29.     new_tty.c_lflag &= ~(ISIG|ICANON|ECHO|ECHOE|ECHOK|ECHONL);
  30.     new_tty.c_cc[VMIN] = 1;
  31.     new_tty.c_cc[VTIME] = 0;
  32.     tcsetattr(0, TCSADRAIN, &new_tty);
  33.     }
  34.     /* suppress flow control */
  35.     Numrows = 0;
  36.     Numcols = 0;
  37.     return 1;
  38. }
  39.  
  40. static void
  41. dumb_end(const struct sessmgr_sw *sm)
  42. {
  43.     if (ttyed && !Suspense)
  44.     tcsetattr(0, TCSADRAIN, &old_tty);
  45. }
  46.  
  47. static void
  48. dumb_suspend(const struct sessmgr_sw *sm)
  49. {
  50.     if (!Suspense++)
  51.     {
  52.     fflush(stdout);
  53.     if (ttyed)
  54.         tcsetattr(0, TCSADRAIN, &old_tty);
  55.     }
  56. }
  57.  
  58. static void
  59. dumb_resume(const struct sessmgr_sw *sm)
  60. {
  61.     extern int Numrows, Numcols;
  62.  
  63.     if (!--Suspense)
  64.     {
  65.     if (ttyed)
  66.         tcsetattr(0, TCSADRAIN, &new_tty);
  67.     Numrows = 0;
  68.     Numcols = 0;
  69.     }
  70. }
  71.  
  72. static int
  73. dumb_swap(const struct sessmgr_sw *sm, void *old, void *new)
  74. {
  75.     int c;
  76.  
  77.     if (old && new)
  78.     {
  79.     c = (int) new - 1;
  80.     printf("\n>>> switching to session %d", c);
  81.     if (Sessions[c].name && *Sessions[c].name)
  82.         printf(": %s", Sessions[c].name);
  83.     else if (Sessions[c].proc->name && *Sessions[c].proc->name)
  84.         printf(" [%s]", Sessions[c].proc->name);
  85.     printf(" (%s)\n", Sestypes[Sessions[c].type]);
  86.     }
  87.     return 0;            /* only the current session can do output */
  88. }
  89.  
  90. static void
  91. dumb_putch(const struct sessmgr_sw *sm, void *dp, int c)
  92. {
  93.     putchar(c);
  94. }
  95.  
  96. static void
  97. dumb_clreol(const struct sessmgr_sw *sm, void *dp)
  98. {
  99. }
  100.  
  101. static void
  102. dumb_rflush(const struct sessmgr_sw *sm, void *dp)
  103. {
  104. }
  105.  
  106. static void
  107. dumb_flush(const struct sessmgr_sw *sm, void *dp)
  108. {
  109.     if (!Suspense)
  110.     fflush(stdout);
  111. }
  112.  
  113. static void *
  114. dumb_create(const struct sessmgr_sw *sm, struct session *sp)
  115. {
  116.     return (void *) (sp - Sessions + 1);
  117. }
  118.  
  119. static void
  120. dumb_destroy(const struct sessmgr_sw *sm, void *dp)
  121. {
  122. }
  123.  
  124. static void
  125. dumb_clrscr(const struct sessmgr_sw *sm, void *dp)
  126. {
  127. }
  128.  
  129. static int
  130. dumb_wherex(const struct sessmgr_sw *sm, void *dp)
  131. {
  132.     return -1;
  133. }
  134.  
  135. static int
  136. dumb_wherey(const struct sessmgr_sw *sm, void *dp)
  137. {
  138.     return -1;
  139. }
  140.  
  141. static void
  142. dumb_window(const struct sessmgr_sw *sm, void *dp, int x1, int y1, int x2,
  143.           int y2)
  144. {
  145. }
  146.  
  147. static void
  148. dumb_gotoxy(const struct sessmgr_sw *sm, void *dp, int x, int y)
  149. {
  150. }
  151.  
  152. static void
  153. dumb_high(const struct sessmgr_sw *sm, void *dp)
  154. {
  155. }
  156.  
  157. static void
  158. dumb_norm(const struct sessmgr_sw *sm, void *dp)
  159. {
  160. }
  161.  
  162. static void
  163. dumb_cursor(const struct sessmgr_sw *sm, void *dp, int c)
  164. {
  165. }
  166.  
  167. /*
  168.  * We define two special characters:  ^C is F10, ^T is F9.  Everything else is
  169.  * passed literally.
  170.  */
  171.  
  172. static int
  173. dumb_kbread(const struct sessmgr_sw *sm, void *dp)
  174. {
  175.     extern int Keyboard;
  176.     unsigned char ch;
  177.     int i;
  178.  
  179.     do
  180.     {
  181.     pwait(&Keyboard);
  182.     }
  183.     while ((i = read(0, &ch, 1)) == 0 || (i == -1 && errno == EWOULDBLOCK));
  184.     if (i < 0)
  185.     {
  186.     tprintf("NOS PANIC: Lost keyboard\n");
  187.     where_outta_here(1);
  188.     }
  189.     if ((i = ch) == 3)
  190.     i = -2;
  191.     else if (i == 20)
  192.     i = -11;
  193.     else if (i == 127)        /* for when the backspace key sends DEL */
  194.     i = 8;
  195.     return i;
  196. }
  197.  
  198. struct sessmgr_sw dumb_sessmgr =
  199. {
  200.     "dumb",
  201.     SM_STDIO,
  202.     dumb_init,
  203.     (char *(*)__FARGS((const struct sessmgr_sw *, char *))) 0,
  204.     dumb_create,
  205.     (char *(*)__FARGS((const struct sessmgr_sw *, void *, char *))) 0,
  206.     dumb_swap,
  207.     dumb_putch,
  208.     dumb_clreol,
  209.     dumb_clrscr,
  210.     dumb_wherex,
  211.     dumb_wherey,
  212.     dumb_window,
  213.     dumb_gotoxy,
  214.     dumb_high,
  215.     dumb_norm,
  216.     dumb_cursor,
  217.     dumb_kbread,
  218.     dumb_destroy,
  219.     0,
  220.     dumb_rflush,
  221.     dumb_flush,
  222.     dumb_suspend,
  223.     dumb_resume,
  224.     dumb_end,
  225. };
  226.  
  227. #endif
  228.